<!doctype html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport"
    content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>axios其他使用</title>
  <link crossorigin="anonymous" href="https://cdn.bootcss.com/twitter-bootstrap/3.3.7/css/bootstrap.min.css"
    rel="stylesheet">
  <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
</head>

<body>
  <div class="container">
    <h2 class="page-header">其他使用</h2>
    <button class="btn btn-primary"> 发送GET请求 </button>
    <button class="btn btn-warning"> 发送POST请求 </button>
    <button class="btn btn-success"> 发送 PUT 请求 </button>
    <button class="btn btn-danger"> 发送 DELETE 请求 </button>
  </div>
  <script>
    //获取按钮
    const btns = document.querySelectorAll('button');

    //发送 GET 请求
    btns[0].onclick = function () {
      // axios()
      axios.request({
        method: 'GET',
        url: 'http://localhost:3000/comments'
      }).then(response => {
        console.log(response);
      })
    }

    //发送 POST 请求
    btns[1].onclick = function () {
      // axios()
      axios.post(
        'http://localhost:3000/comments',
        {
          "body": "喜大普奔",
          "postId": 2
        }).then(response => {
          console.log(response);
        })
    }

    /**
     * axios({
     *      url: '/post',
     *      //  /post?a=100&b=200
     *      //  /post/a/100/b/200
     *      //  /post/a.100/b.200
     *      params: {
     *          a:100,
     *          b:200
     *      }
     * })
     * 
     * 
     *  
     */

  </script>
</body>

</html>